// pages/index/t_class/stufent/homework/upHomeWork/upHomeWork.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    optionsId :0 , 
    title:'',
    content:'',
    fileList:[],
    picture:'',
    classId :'',
    student:'',
    details :[],
    list:[],
    current:'',
    image : "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      optionsId: options.id
      ,student:options.student
    })
    this.getHomeWorkDetails()
  },

  /**
   * 
   */
  downloadFile: function(e) {
    wx.downloadFile({
      // 示例 url，并非真实存在
      url: this.data.image,
      success: function (res) {
        const filePath = res.tempFilePath
        wx.openDocument({
          filePath: filePath,
          success: function (res) {
            console.log('打开文档成功')
          }
        })
      }
    })
  },
  /**
   * 获取 作业情况  
   */
  getHomeWorkDetails() { 
    let userInfo =  wx.getStorageSync('userInfo')
    wx.request({
      url: 'http://localhost:9090/api/homeWorkStudent/detail?id=' + this.data.student +'&homeId=' + this.data.optionsId ,
      method:'get',
      success:res=>{
        // console.log(res);
        this.setData({
          list:res.data.data,
          image : res.data.data[0].image
        })
      }
    })
  },
  submitClick() { 
    if(this.data.title == ''){
      wx.showToast({
        title: '请输入要打的分数',
        icon:'none'
      })
      return
    }
    let userInfo =  wx.getStorageSync('userInfo')

    wx.request({
      url: 'http://localhost:9090/api/homeWorkStudent/addScore?id=' +  this.data.student  +'&homeId=' + this.data.optionsId + '&score=' + this.data.title ,
      method:'get',
      success:res=>{
        if(res.data.code == 200 ) {
          wx.showToast({
            title: '提交成功！',
            icon:'none'
          })
        }
      }
    })
  },
  blurTitle(e){
    this.setData({
      title:e.detail.value
    })
  },

  /**
   * 
   */
  //预览图片，放大预览
  preview(event) {
    let currentUrl = event.currentTarget.dataset.src
    wx.previewImage({
      current: currentUrl, // 当前显示图片的http链接
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})